package dev.entao.travel

import dev.entao.core.HttpContext
import dev.entao.core.HttpPages
import dev.entao.html.text
import dev.entao.log.logd
import dev.entao.page.bs.DashboardPage
import dev.entao.page.bs.DialogRender
import dev.entao.travel.model.Account

open class AdminPages(context: HttpContext) : HttpPages(context) {



    protected open fun dashboard(block: DashboardPage.() -> Unit) {
        val accId = context.accountID
        val acc: Account? = if (accId == 0) {
            null
        } else {
            Account.oneByKey(accId)
        }
        val startTime = System.currentTimeMillis()
        DashboardPage(context).apply {
            title(context.app.appName)
            topBar.brand {
                +context.app.appName
            }

            //TODO 注销菜单
            if (acc == null) {
                topBar.user {
                    text("登录")
                }
            } else {
                topBar.user {
                    text(acc.name)
                    classAdd("active")
                }
            }
            this.block()
        }.send()
        val endtime = System.currentTimeMillis()
        logd("Time: ${endtime - startTime}")
    }

    fun sendDialog(block: DialogRender.() -> Unit) {
        DialogRender(context).apply(block).send()
    }

    companion object {
        const val PAGE_SIZE = 50
    }

}